package com.example.trafficsystem.controller;

import com.example.trafficsystem.entity.Task;
import com.example.trafficsystem.entity.TrainingDocument;
import com.example.trafficsystem.entity.TrainingPlan;
import com.example.trafficsystem.service.TaskService;
import com.example.trafficsystem.service.TrainingPlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

@RestController
@RequestMapping("/trainingPlan")
@CrossOrigin
public class TrainingPlanController {
    @Autowired
    private TrainingPlanService trainingPlanService;
    @Autowired
    private TaskService taskService;

    @GetMapping("/{organizationId}")
    public List<TrainingPlan> getTrainingPlans(@PathVariable Long organizationId) {
        List<TrainingPlan> trainingPlans = trainingPlanService.getAllTrainingPlans(organizationId);
        if (trainingPlans.isEmpty()) {
            throw new ResponseStatusException(HttpStatus.NOT_FOUND, "未找到相关的培训计划");
        }
        return trainingPlans;
    }
    //获取培训的所有任务点
    @GetMapping("/{trainingPlanId}/tasks")
    public List<Task> getTasksByTrainingPlan(@PathVariable Long trainingPlanId) {
        return taskService.findDocumentsByTrainingPlan(trainingPlanId);
    }
    //获取任务点的详细信息
    @GetMapping("/task/{taskId}")
    public Task getTaskDetail(@PathVariable Long taskId) {
        return taskService.findDocumentById(taskId);
    }

}
